package pokerbot.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Table {

    private final List<Card> cards = new ArrayList<>(5);
    private final Map<Integer, Player> players = new HashMap<>();
    private final Deck deck = new Deck();
    private final static int POSITION = -1;
    private int playersCount = 0;

    public Table() {
    }
    
    public void addPlayers(List<Player> players) {
        for (Iterator<Player> it = players.iterator(); it.hasNext();) {
            this.players.put(playersCount, it.next());
            playersCount++;
        }
    }

    public List<Card> getCards() {
        return cards;
    }

    public void removeAllCards() {
        for (int i = 0; i < cards.size(); i++) {
            cards.remove(i);
        }
    }

    public void addCard(Card card) {
        cards.add(card);
    }

    public Map<Integer, Player> getPlayers() {
        return players;
    }

    public void addPlayer(int position, Player player) {
        players.put(position, player);
        playersCount++;
    }

    public void deletePlayer(int position) {
        players.remove(position);
    }

    public Deck getDeck() {
        return deck;
    }

    public static int getPosition() {
        return POSITION;
    }

    public int getPlayersCount() {
        return playersCount;
    }
    
    @Override
    public String toString() {
        return new StringBuilder("deck = ").append(deck)
                .append("\ncards = ").append(cards)
                .append("\nplayers = ").append(players).toString();
    }

}
